package cn.kshost.zqyg.manager.controller;

import cn.kshost.zqyg.manager.service.SysRoleService;
import cn.kshost.zqyg.model.dto.system.SysRoleDto;
import cn.kshost.zqyg.model.entity.system.SysRole;
import cn.kshost.zqyg.model.entity.system.SysUser;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/sysRole")
@Tag(name = "后台系统角色接口")
public class SysRoleController {


    @Autowired
    private SysRoleService sysRoleService;
    @Operation(summary = "后台模糊查询角色信息列表")
    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysRole>>  findByPage(SysRoleDto sysRoleDto, @PathVariable int pageNum, @PathVariable int pageSize,@RequestHeader String token) throws JsonProcessingException {
        PageInfo<SysRole> pageInfo =  sysRoleService.findByPage(sysRoleDto,pageNum,pageSize);
        System.out.println("token = " + token);
        return Result.build(pageInfo,200,"查询成功");
    }

    @Operation(summary = "新增角色")
    @PostMapping("/saveSysRole")
    public Result saveSysRole(@RequestBody SysRole sysRole){
        sysRoleService.saveSysRole(sysRole);
        return Result.build(null,200,"添加成功");
    }

    @Operation(summary = "修改角色")
    @PutMapping("/upDateSysRole")
    public Result upDateSysRole(@RequestBody SysRole sysRole){
        sysRoleService.modifySysRole(sysRole);
        return Result.build(null,200,"修改成功");
    }

    @Operation(summary = "删除角色")
    @DeleteMapping("/deleteSysRole")
    public Result deleteSysRole(@RequestBody SysRole sysRole){
        sysRoleService.removeSysRole(sysRole);
        return Result.build(null,200,"删除成功");
    }
    @Operation(summary = "查询所有角色")
    @GetMapping("/getAllRole")
    public Result<List<SysRole>> getAllRole(){
        List<SysRole> roles =  sysRoleService.getAllRoles();
        return Result.build(roles, ResultCodeEnum.SUCCESS);
    }
}
